package com.qst.system.controller;

import com.qst.common.core.controller.BaseController;
import com.qst.common.core.domain.AjaxResult;
import com.qst.common.core.page.TableDataInfo;
import com.qst.system.domain.vo.AptitudeVo;
import com.qst.system.service.IAptitudeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/aptitude")
public class AptitudeController extends BaseController {

    @Autowired
    private IAptitudeService aptitudeService;

    @PreAuthorize("@ss.hasPermi('system:aptitude:list')")
    @GetMapping("/list")
    public TableDataInfo selectAptitudeList(AptitudeVo aptitude){
        startPage();
        List<AptitudeVo> aptitudeVos = aptitudeService.selectAptitudeList(aptitude);
        return getDataTable(aptitudeVos);
    }

    @PreAuthorize("@ss.hasPermi('system:aptitude:edit')")
    @GetMapping(value = "/{aptId}")
    public AjaxResult selectAptitudeById(@PathVariable("aptId") Long aptId){
        AptitudeVo aptitudeVo = aptitudeService.selectAptitudeById(aptId);
        return AjaxResult.success(aptitudeVo);
    }

    @PreAuthorize("@ss.hasPermi('system:aptitude:list')")
    @GetMapping("/comName")
    public AjaxResult getAptitudeCompanyName() {
        // 调用Service层获取企业列表（数据格式：List<{comId, comName}>）
        return AjaxResult.success(aptitudeService.selectCompanyNameList());
    }

    @PreAuthorize("@ss.hasPermi('system:aptitude:add')")
    @PostMapping
    public AjaxResult add(@RequestBody AptitudeVo aptitude){
        System.out.println("==============================");
        System.out.println("aptitude:" + aptitude.toString());
        return toAjax(aptitudeService.insertAptitude(aptitude));
    }

    @PreAuthorize("@ss.hasPermi('system:aptitude:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody AptitudeVo aptitude){
        return toAjax(aptitudeService.updateAptitude(aptitude));
    }

    @PreAuthorize("@ss.hasPermi('system:aptitude:remove')")
    @DeleteMapping("/{aptIds}")
    public AjaxResult remove(@PathVariable Long[] aptIds){
        if (aptIds.length == 1){
            return toAjax(aptitudeService.deleteAptitudeById(aptIds[0]));
        }
        return toAjax(aptitudeService.deleteAptitudeByIds(aptIds));
    }
}